package com.me.batm.models;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.me.batm.GameConstants.Direction;

public class Person extends LivingGameObject{
	public Vector2 direction;
	public boolean teleport;
	public float teletransportTime;
	
	public Person(float x, float y, float width, float height,Vector2 direction) {
		super(x, y, width, height, new Vector2(0f,0f));
		this.direction = direction;
		teleport = false;
		
		teletransportTime = 100f;
	}
	public void teletransport(boolean [][]walkMap, float layerWidth, float layerHeight, float tileWidth,
		float tileHeight, Array<GameEntity> entities) {
		int x, y;
		int tries = 0;
		boolean teleportIntersection = false;
		while (this.teleport) {
			teleportIntersection = false;
			x = (int) Math.floor(Math.random() * layerWidth);
			y = (int) Math.floor(Math.random() * layerHeight);
			//System.out.println("Coords: " + x + " " + y);
			
			if (walkMap[x][y] == true)  {
				this.shape.x = y * tileWidth + 2;
				this.shape.y = (layerHeight - x - 1) * tileHeight + 2;
			for (int i = 0; i < entities.size && teleportIntersection == false; i += 1) {
				if (entities.get(i).shape.overlaps(this.shape)) {
					teleportIntersection = true;
				}
			}
			//System.out.println(player.shape.x + " " + player.shape.y);
				if (teleportIntersection == false) {
					this.teleport = false;				
				}
			}
		}
		//teletransportTime = 0f;
	}
	public Vector2 getCenterPosition(){
		return new Vector2(shape.x + shape.width/2f,shape.y+shape.height/2f);
	}
	
	public Direction getDirection(){
		if(direction.x > 0)return Direction.RIGHT;
		if(direction.x < 0)return Direction.LEFT;
		if(direction.y > 0)return Direction.UP;
		if(direction.y < 0)return Direction.DOWN;
		
		return Direction.DOWN;
	}
	
}
